{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true,
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "best_x: [2.02735967e-05 5.00065332e-02 7.26102075e-06] best_y 5.064244416626108e-10\n"
     ]
    },
    {
     "data": {
      "text/plain": "<Figure size 432x288 with 1 Axes>",
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD5CAYAAAA3Os7hAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAWM0lEQVR4nO3df5BdZX3H8c9n997du8nuJoQsyCTZRCG2ij9AV0z8MeLPBsqU2qEjWEFtbQqDih1sq8xUp+04taO11aJmIlCkUtAqauoElbFYUCZAEoP8CLRRfqVBEhLIZtlkN7v77R/3LLm52c29u3s3N+ec92vmzt57zrP3fh8gnzw89znPcUQIAJB+Lc0uAADQGAQ6AGQEgQ4AGUGgA0BGEOgAkBEEOgBkRKFWA9slSXdIak/afzsiPl3VxpK+KOlcSYOSPhARm4/2vgsXLoxly5ZNs2wAyKdNmzY9ExE9E52rGeiShiS9LSIGbBcl/cz2rRGxoaLNOZKWJ4/XS/pq8nNSy5Yt08aNG+vqAACgzPbjk52rOeUSZQPJy2LyqL4a6XxJNyRtN0iab/uU6RYMAJi6uubQbbfa3iJpp6TbIuLuqiaLJD1Z8Xp7cgwAcIzUFegRMRoRZ0haLOks26+oauKJfq36gO3Vtjfa3rhr164pFwsAmNyUVrlExHOSfippVdWp7ZKWVLxeLGnHBL+/NiL6IqKvp2fCOX0AwDTVDHTbPbbnJ887JL1D0sNVzdZJusRlKyTtjYinGl0sAGBy9axyOUXS1223qvwXwLci4ge2L5WkiFgjab3KSxa3qbxs8YOzVC8AYBI1Az0ifinpzAmOr6l4HpIub2xpAICp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Q5zG+MiFuSw6nvlyRFxHOSfqrydx9p7tMbJf2e7cdUnrZ8m+1vKN19kiRFxI7k505J31V5mjb1/apX2gK9nvubptk6Se9Pnr9f0vebWMuUuTwUv1bS1oj4QsWp1PbLdk8yMpftDknvkPSwUtyniPhkRCyOiGUq/xn6r4h4n1LcJ0myPdd21/hzSe+S9IBS3q+pSN2FRbbPVXn+b/z+pp9pbkXTY/smSWervBvc05I+Lel7kr4lqVfSE5L+MCKqvzg9btl+k6Q7Jd2vQ3OzV6k8j57Kftl+lcpfpLWqPAD6VkT8re0TldI+VUqmXD4eEeelvU+2X6LyqFwqTyf/e0R8Ju39morUBToAYGJpm3IBAEyCQAeAjCDQASAjCHQAyAgCHQAygkAHgIwg0AEgIwh0AMiI/weowLTXMM4MzgAAAABJRU5ErkJggg==\n"
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "demo_func = lambda x: x[0] ** 2 + (x[1] - 0.05) ** 2 + x[2] ** 2\n",
    "\n",
    "from sko.SA import SA\n",
    "\n",
    "sa = SA(func=demo_func, x0=[1, 1, 1], T_max=1, T_min=1e-9, L=300, max_stay_counter=150)\n",
    "best_x, best_y = sa.run()\n",
    "print('best_x:', best_x, 'best_y', best_y)\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "import pandas as pd\n",
    "\n",
    "plt.plot(pd.DataFrame(sa.best_y_history).cummin(axis=0))\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10920\n"
     ]
    }
   ],
   "source": [],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "from sko.SA import SA\n",
    "\n",
    "sa = SA(func=demo_func, x0=[0.58294678, 0.32422638, 0.30072021, 0.04949951, 0.74310493,\n",
    "                            0.26721382, 0.05133057, 0.72602844, -0.12939453, -0.73083496], T_max=1, T_min=1e-9, L=300,\n",
    "        max_stay_counter=150)\n",
    "best_x, best_y = sa.run()\n",
    "print('best_x:', best_x, 'best_y', best_y)\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "import pandas as pd\n",
    "\n",
    "plt.plot(pd.DataFrame(sa.best_y_history).cummin(axis=0))\n",
    "plt.show()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}